/*
Arm Tracker and Glove Demo by Noah Zerkin (noazark AT gmail.com) 2009
Released under GNU GPLv3.0 http://www.opensource.org/licenses/gpl-3.0.html
*/

class Target{

  float[] trajectory = new float[3];
  float[] currentCoords = new float[3];
  float orbitPosition = 0;
  int altitude = 0;
  int targetRadius = 0;
  int orbitRadius = 0;
  float orbitSpeed = 0.0;

  Target(int distance, int height, float orbit, float speed, int targetSize){
    targetRadius = targetSize;
    altitude = height;
    orbitRadius = distance;
    orbitPosition = orbit;
    orbitSpeed = speed;
  }

  void update(){
    orbitPosition += orbitSpeed * TWO_PI;
    rotateY(orbitPosition);
    translate(orbitRadius, 0, -altitude);
    currentCoords[0] = modelX(0,0,0);
    currentCoords[1] = modelY(0,0,0);
    currentCoords[2] = modelZ(0,0,0);
  }

  boolean isHit(){
    boolean hit = false;
    for(int i = bullets.size()-1; i >= 0; i--) {
      Bullet thisBullet = (Bullet)bullets.get(i);
      float[] bulletPosition = thisBullet.getPosition();
      if(dist(currentCoords[0],currentCoords[1],currentCoords[2],thisBullet.getX(),thisBullet.getY(),thisBullet.getZ()) <= targetRadius){
        hit = true;
      }
    }
    return hit;
  }

  float[] getPosition(){
    return currentCoords;
  }
  
  float getOrbitPosition(){
    return orbitPosition;
  }
  
  int getAltitude(){
    return altitude;
  }
  
  float getTargetSpeed(){
    return orbitSpeed;
  }
  
  int getOrbitRadius(){
    return orbitRadius;
  }
  
  int getTargetRadius(){
    return targetRadius;
  }

  void display(){
    pushMatrix();
    translate(currentCoords[0], currentCoords[1], currentCoords[2]);
    sphere(targetRadius);
    popMatrix();
  }

}
